package com.wenhui.schoolyardinfo.square.adapter;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.customview.CircleImageView;
import com.wenhui.schoolyardinfo.firstpage.adapter.CommentsAdapter;
import com.wenhui.schoolyardinfo.square.bean.InterestedPersonBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/24 09:52
 * introduce :
 */

public class InterestedPersonAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<InterestedPersonBean> interestedPersonBeanList = new ArrayList<>();
    private static final int HEADER_VIEW_TYPE = 1;
    private static final int CONTENT_VIEW_TYPE = 2;
    private static final int FOOTER_VIEW_TYPE = 3;

    public InterestedPersonAdapter(Context context) {
        this.context = context;
    }

    public InterestedPersonAdapter(Context context, List<InterestedPersonBean> interestedPersonBeanList) {
        this.context = context;
        this.interestedPersonBeanList = interestedPersonBeanList;
    }

    public void clearData() {
        interestedPersonBeanList.clear();
        notifyDataSetChanged();
    }

    public void addAllData(List<InterestedPersonBean> interestedPersonBeanList) {
        this.interestedPersonBeanList.addAll(interestedPersonBeanList);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        switch (viewType) {
            case HEADER_VIEW_TYPE:
                view = LayoutInflater.from(context).inflate(R.layout.item_interested_person_header, null);
                return new HeaderHolder(view);
            case CONTENT_VIEW_TYPE:
                view = LayoutInflater.from(context).inflate(R.layout.item_interested_person_content, null);
                return new ContentHolder(view);
            default:
                view = LayoutInflater.from(context).inflate(R.layout.item_interested_person_footer, null);
                return new FooterHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HeaderHolder) {
            HeaderHolder headerHolder = (HeaderHolder) holder;
            Glide.with(context).load(interestedPersonBeanList.get(position).getHeadPortraitUrl()).into(headerHolder.imvHeadPortrait);
            headerHolder.tevName.setText(interestedPersonBeanList.get(position).getName());
        } else if (holder instanceof ContentHolder) {
            ContentHolder contentHolder = (ContentHolder) holder;
            Glide.with(context).load(interestedPersonBeanList.get(position).getHeadPortraitUrl()).into(contentHolder.imvHeadPortrait);
            contentHolder.tevName.setText(interestedPersonBeanList.get(position).getName());
        } else {
            FooterHolder footerHolder = (FooterHolder) holder;
            Glide.with(context).load(interestedPersonBeanList.get(position).getHeadPortraitUrl()).into(footerHolder.imvHeadPortrait);
            footerHolder.tevName.setText(interestedPersonBeanList.get(position).getName());
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return HEADER_VIEW_TYPE;
        } else if (position == interestedPersonBeanList.size() - 1) {
            return FOOTER_VIEW_TYPE;
        } else {
            return CONTENT_VIEW_TYPE;
        }
    }

    @Override
    public int getItemCount() {
        return interestedPersonBeanList.size();
    }

    protected class HeaderHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.imv_head_portrait)
        CircleImageView imvHeadPortrait;
        @BindView(R.id.tev_name)
        TextView tevName;

        private HeaderHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            imvHeadPortrait.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.imv_head_portrait:

                    break;
                default:
                    break;
            }
        }
    }

    protected class ContentHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.imv_head_portrait)
        CircleImageView imvHeadPortrait;
        @BindView(R.id.tev_name)
        TextView tevName;

        private ContentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            imvHeadPortrait.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.imv_head_portrait:

                    break;
                default:
                    break;
            }
        }
    }

    protected class FooterHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.imv_head_portrait)
        CircleImageView imvHeadPortrait;
        @BindView(R.id.tev_name)
        TextView tevName;

        private FooterHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            imvHeadPortrait.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.imv_head_portrait:

                    break;
                default:
                    break;
            }
        }
    }

}
